﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ConquerServer_Basic
{
    public class Monster
    {
        public uint ID;
        public string Name;
        public byte Type;
        public ushort Lookface;
        public uint Life;
        public uint AttackMin;
        public uint AttackMax;
        public uint Defence;
        public uint Dexterity;
        public uint Dodge;
        public ushort AttackRange;
        public ushort ViewRange;
        public uint EscapeLife;
        public uint MoveSpeed;
        public ushort Level;
        public byte AttackUser;
        public uint DropMoney;
        public uint DropItemType;
        public uint DropHP;
        public uint DropMP;
        public byte MagicType;
        public uint MagicDefence;
        public uint MagicHitRate;
        public byte AIType;
        public uint Defence2;
        public uint ExtraExp;

        public static void Load()
        {
            IniFile cq_monstertype = new IniFile();
            foreach (string file in Directory.GetFiles(Database.DatabasePath + "\\cq_monstertype\\"))
            {
                cq_monstertype.FileName = file;
                Monster mob = new Monster();
                mob.ID = cq_monstertype.ReadUInt32("cq_monstertype", "id", 0);
                mob.Name = cq_monstertype.ReadString("cq_monstertype", "name", "?");
                mob.Type = cq_monstertype.ReadByte("cq_monstertype", "type", 0);
                mob.Lookface = cq_monstertype.ReadUInt16("cq_monstertype", "lookface", 0);
                mob.Life = cq_monstertype.ReadUInt32("cq_monstertype", "life", 0);
                mob.AttackMax = cq_monstertype.ReadUInt32("cq_monstertype", "attack_max", 0);
                mob.AttackMin = cq_monstertype.ReadUInt32("cq_monstertype", "attack_min", 0);
                mob.Defence = cq_monstertype.ReadUInt32("cq_monstertype", "defence", 0);
                mob.Dexterity = cq_monstertype.ReadUInt32("cq_monstertype", "dexterity", 0);
                mob.Dodge = cq_monstertype.ReadUInt32("cq_monstertype", "dodge", 0);
                mob.AttackRange = cq_monstertype.ReadUInt16("cq_monstertype", "attack_range", 0);
                mob.ViewRange = cq_monstertype.ReadUInt16("cq_monstertype", "view_range", 0);
                mob.EscapeLife = cq_monstertype.ReadUInt32("cq_monstertype", "escape_life", 0);
                mob.Level = cq_monstertype.ReadUInt16("cq_monstertype", "level", 0);
                mob.AttackUser = cq_monstertype.ReadByte("cq_monstertype", "attack_user", 0);
                mob.DropMoney = cq_monstertype.ReadUInt32("cq_monstertype", "drop_money", 0);
                mob.DropItemType = cq_monstertype.ReadUInt32("cq_monstertype", "drop_itemtype", 0);
                mob.DropHP = cq_monstertype.ReadUInt32("cq_monstertype", "drop_hp", 0);
                mob.DropMP = cq_monstertype.ReadUInt32("cq_monstertype", "drop_mp", 0);
                mob.MagicType = cq_monstertype.ReadByte("cq_monstertype", "magic_type", 0);
                mob.MagicHitRate = cq_monstertype.ReadUInt32("cq_monstertype", "magic_hitrate", 0);
                mob.MagicDefence = cq_monstertype.ReadUInt32("cq_monstertype", "magic_def", 0);
                mob.AIType = cq_monstertype.ReadByte("cq_monstertype", "ai_type", 0);
                mob.Defence2 = cq_monstertype.ReadUInt32("cq_monstertype", "defence2", 0);
                mob.ExtraExp = cq_monstertype.ReadUInt32("cq_monstertype", "extra_exp", 0);

                Kernel.Mobs.Add(mob.ID, mob);
            }

            Console.WriteLine("Monsters Loaded: "+ Kernel.Mobs.Count);
        }
    }
}
